//
//  WPAbountUsViewController.m
//  ZhongChouPingTai
//
//  Created by WeiPan on 16/4/4.
//  Copyright © 2016年 WPJoe. All rights reserved.
//

#import "WPAbountUsViewController.h"
#import "UIColor+HexString.h"

@interface WPAbountUsViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UIImageView * logoImageView;/**< 图标 */
@property (nonatomic, strong) UILabel * versonLabel;/**< 版本信息 */
@property (nonatomic, strong) UITableView * abountTableView;/**< 关于表格视图 */
@property (nonatomic, strong) NSMutableArray * abountArr;/**< 关于数据源 */
- (void)initializeDataSource; /**< 初始化数据源 */
- (void)initializeUserInterface; /**< 初始化用户界面 */


@end

@implementation WPAbountUsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initializeDataSource];
    [self initializeUserInterface];
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
    self.navigationController.navigationBarHidden = NO;
}
#pragma mark - init
- (void)initializeDataSource {
    self.abountArr = [NSMutableArray arrayWithArray:@[@[@"服务条款", @""], @[@"联系邮箱", @"189691891@qq.com"], @[@"联系电话", @"18602855082"]]];
}
- (void)initializeUserInterface {
    [self.view addSubview:self.logoImageView];
    [self.view addSubview:self.versonLabel];
    [self.view addSubview:self.abountTableView];
    if ([self.abountTableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.abountTableView setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([self.abountTableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.abountTableView setLayoutMargins:UIEdgeInsetsZero];
    }
}
#pragma mark - 协议UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _abountArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"123"];
    }
    if (indexPath.row == 0) {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.textLabel.font = [UIFont systemFontOfSize:10*DHFlexibleHorizontalMutiplier()];
    cell.detailTextLabel.font = [UIFont systemFontOfSize:10*DHFlexibleHorizontalMutiplier()];
    cell.textLabel.text = _abountArr[indexPath.row][0];
    cell.detailTextLabel.text = _abountArr[indexPath.row][1];
    return cell;
}
#pragma mark - UITableViewDelegate
//设置每一行高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 40*DHFlexibleHorizontalMutiplier();
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}
//用户点击了某一行
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        [self pushToNextController:[[NSClassFromString(@"WPUserProtocolViewController") alloc]init] withVCTitle:@"服务协议"];
    }
}
#pragma mark -getter
- (UIImageView *)logoImageView {
    if (!_logoImageView) {
        _logoImageView = ({
            UIImageView * view = [[UIImageView alloc]initWithFrame:CGRectMake(130*DHFlexibleHorizontalMutiplier(), 124*DHFlexibleVerticalMutiplier(), 57*DHFlexibleHorizontalMutiplier(), 57*DHFlexibleVerticalMutiplier())];
            view.image = IMAGE_NAME(@"abountUsLogo");
            view.layer.cornerRadius = 5*DHFlexibleHorizontalMutiplier();
            view.layer.masksToBounds = YES;
            view;
        });
    }
    return _logoImageView;
}
- (UILabel *)versonLabel {
    if (!_versonLabel) {
        _versonLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.logoImageView.frame), SCREEN_SIZE.width, 30)];
            NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
            NSString *app_Name = [infoDictionary objectForKey:@"CFBundleName"];
            // app版本
            NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
            lab.text =  [NSString stringWithFormat:@"%@ v%@", app_Name, app_Version];
            lab.textAlignment = NSTextAlignmentCenter;
            lab.textColor = [UIColor colorWithHexString:@"#3d3d3d"];
            lab.font = [UIFont systemFontOfSize:10*DHFlexibleHorizontalMutiplier()];
            lab;
        });
    }
    return _versonLabel;
}
- (UITableView *)abountTableView {
    if (!_abountTableView) {
        _abountTableView = ({
            UITableView * tableview = [[UITableView alloc]initWithFrame:CGRectMake(10, 224*DHFlexibleVerticalMutiplier(), SCREEN_SIZE.width - 20, 120*DHFlexibleHorizontalMutiplier()) style:UITableViewStylePlain];
            tableview.dataSource = self;
            tableview.delegate = self;
            tableview.tableFooterView = [UIView new];
            tableview.pagingEnabled = NO;
            tableview.separatorColor = COLOR_RGB(211, 211, 211, 1);
            tableview.backgroundColor = [UIColor whiteColor];
            tableview.scrollEnabled = NO;
            tableview;
        });
    }
    return _abountTableView;
}
@end
